<template>
    <div class="order">
        <!-- 查询条件 -->
        <el-form :inline="true" :model="formInline" class="demo-form-inline" size="mini">
            <el-form-item label="客户姓名">
                <el-input v-model="formInline.name" placeholder="输入姓名"></el-input>
            </el-form-item>
            <el-form-item label="所属辅导">
                <el-input v-model="formInline.instructorName" placeholder="输入辅导名"></el-input>
            </el-form-item>
            <el-form-item label="所属区域">
                <el-select v-model="formInline.area" placeholder="请选择">
                    <el-option label="全部" value=""></el-option>
                    <el-option
                            v-for="item in areasList"
                            :key="item.id"
                            :label="item.title"
                            :value="item.id">
                    </el-option>

                </el-select>
            </el-form-item>
            <el-form-item label="客户状态">
                <el-select v-model="formInline.custState" placeholder="请选择">
                    <el-option label="全部" value=""></el-option>
                    <el-option label="待审核" value="0"></el-option>
                    <el-option label="已审核" value="1"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>

        <!--列表-->
        <el-table :data="paramData" stripe highlight-current-row v-loading="listLoading" style="width: 100%;">
            <el-table-column prop="name" label="客户姓名" align="center"></el-table-column>
            <el-table-column prop="mobile" label="手机号码" align="center"></el-table-column>
            <el-table-column prop="area" label="所属区域" align="center"></el-table-column>
            <el-table-column prop="createDate" label="注册时间" align="center"></el-table-column>
            <el-table-column prop="state" label="客户状态"  :formatter="formatState" align="center"></el-table-column>
            <el-table-column prop="instructorName" label="所属辅导" align="center"></el-table-column>
            <el-table-column prop="instructorMobile" label="辅导手机号" align="center"></el-table-column>

        </el-table>

        <!--工具条-->
        <el-col :span="24" class="toolbar">
            <el-pagination
                    background
                    layout="prev, pager, next" :page-size="10"
                    :total="total"
                    style="float:right;"
                    @current-change="changePage"
                    :current-page.sync="currentPage">
            </el-pagination>
        </el-col>
    </div>
</template>
<script>
    import util from '../../common/js/util'
    import * as api from '../../api/enjoylove_api';
    import ElOption from "../../../node_modules/element-ui/packages/select/src/option.vue";
    export default {
        components: {ElOption},
        data() {
            return {
                areasList:[],//区域数据
                listLoading: false,
                page: 1,
                total: 0,
                currentPage :1,
                paramData: [],//列表数据
                formInline: {
                    name: '',
                    instructorName: '',
                    area: '',
                    custState: '',
                }
            }

        },
        methods:{
                //获取列表数据
                getData (){
                    this.listLoading = true;
                    let  params={
                        page:this.currentPage,
                        name:this.formInline.name,
                        instructor:this.formInline.instructorName,
                        area:this.formInline.area,
                        state:this.formInline.custState
                    }
                    api.getCustomerList(params).then((res) => {
                        this.listLoading = false;//停止加载
                        var _resData  =JSON.parse(res.data) ;
                        if(!_resData.status){
                            if(_resData.success){
                                //成功
                                this.paramData = _resData.data.customerPage.content;
                                this.total = _resData.data.customerPage.totalElements;
                            }else {
                                this.$message.error(_resData.message);
                            }
                        }else{
                            if(_resData.status == 401){
                                this.$router.push('/login');
                            }
                        }


                    });
                },
            //选择页码
                changePage(val){
                    this.currentPage = val;
                    this.getData();
                },
            formatState(row){
                    var stateString = '';
                    if(row.state==0){
                        stateString = '待审核'
                    } else  if (row.state==1){
                        stateString = '已审核'
                    } else {
                        stateString = '审核未通过'
                    }
                    return stateString;
            },
            //获取区域 list
            getAreasList(){
                let params ={};
                api.getInstructorAreas(params).then((res)=>{
                    var _resData  =JSON.parse(res.data) ;
                    if(!_resData.status){
                        if(_resData.success){
                            this.areasList = _resData.data.areas;
                        }else {
                            this.$message.error(_resData.message);
                        }
                    }else {
                        if (_resData.status == 401) {
                            this.$router.push('/login');
                        }
                    }
                });
            },
            //查询
            onSubmit(){
                this.currentPage =1;
                this.getData();
            }

        },
        mounted() {
                this.$nextTick(function () {
                    this.getData();
                    this.getAreasList();
                })

        }
    }
</script>